//引入公共文件
// document.write("<script language=javascript src=\"__ASSETS__/js/common.js\"><\/script>");
function checkLogin() {
    $token = getData('scj_token');
    if (isEmptyString($token)){
        //跳转到登录
        $(window).attr('location',host+'/index/index/login');
        return;
    }
    var userString = getData('scj_user');
    var userObj = JSON.parse(userString);
    var tel = userObj.mobile;

    var reg = /^(\d{3})\d{4}(\d{4})$/;
    tel = tel.replace(reg, "$1****$2");
    // console.log(tel);
    $('#yu-title').html(userObj.nickname+'【'+tel+'】');

    var string = '测试字符串272604545@qq.com';
    var enstring = Base64.encode(string);
    var destring = Base64.decode(enstring);
    showy('orstring: ' + string);
    showy('enstring: ' + enstring);
    showy('destring: ' + destring);
}
//直接执行检查操作？还是等页面加载的差不多了，在检查？
checkLogin();

window.onload = function () {
    //初始化后面需要用到的数据！
    saveData('last_show_id',0);
};

function clearData(){
    //清除类型数据
    removeData('type_data');
    //清除url数据
    removeData('url_data');
    //清除当前typeid数据
    removeData('last_show_id');
    //清除当前token数据
    removeData('scj_token');
    //清除当前user数据
    removeData('scj_user');
    //清楚用户操作数据
    removeData('cur_url_data');
    removeData('base_type_id');
    removeData('user_base_type_id');
    removeData('move_type_to');
    removeData('currentPageDataMsg');
    removeData('emailcode');
    removeData('cur_deal_url_id');
    removeData('cur_deal_type_id');
    removeData('cur_deal_set_type');
    removeData('cur_deal_msg_id');

    removeData(YuKey.pas_status);
    removeData(YuKey.pas_action);
    removeData(YuKey.pas_action_id);
    removeData(YuKey.pas_email_code);
    removeData(YuKey.passtring);
    //删除用户信息
    $.cookie('scj_token',null);
    $.cookie('scj_user',null);
}

//点击退出登录的时候的一个动效
$('.btn-logout').click(function () {
    var $btn = $(this)
    $btn.button('loading');

    var host = 'http://scj.web.co';
    var url = host + '/api/Login/loginOut';
    var token = $.cookie('scj_token');
    if (isEmptyString(token)){
        token = getData('scj_token');
    }

    $.post(url, {token: token}, function (data) {
        if (data != null && data.code != null) {
            if (data.code == 200) {
                //按钮样式还原
                $btn.button('reset');

                // 退出登录成功！
                //清除本地用户的所有数据
               clearData();
                // console.log(user);
                // console.log(user.id);
                //跳转登录
                $(window).attr('location',host+'/index/index/login');

            } else {
                // showTips(data.msg);
                alert(data.msg);
                $btn.button('reset');
            }
        }else{
            $btn.button('reset');
            alert('退出登录失败！');
        }
    },"json");

    // setTimeout(function(){
    //
    // }, 5000);
});

//点击全部的时候的一个动效
$('.btn-all').click(function () {
    //跳转用户详细数据页
    var mu = host+'/index/UserData/userdetail';
    var parames = new Array();
    var token = token;
    var userString = userString;
    if (isEmptyString(token)){
        token = getData('scj_token');
        userString = getData('scj_user');
    }
    showy('userString: ' + userString);
    showy('token: ' + token);

    parames.push({ name: "userstring", value: userString});
    parames.push({ name: "token", value: token});
    Post(mu, parames);

});

//点击类型的时候的一个动效
$('.btn-type-user').click(function () {
    //跳转用户详细数据页
    var mu = host+'/index/UserData/usertype';
    var parames = new Array();
    var token = token;
    var userString = userString;
    if (isEmptyString(token)){
        token = getData('scj_token');
        userString = getData('scj_user');
    }
    parames.push({ name: "userstring", value: userString});
    parames.push({ name: "token", value: token});
    Post(mu, parames);

});

//点击url的时候的一个动效
$('.btn-url-user').click(function () {
    //跳转用户详细数据页
    // var mu = host+'/index/UserData/usertype';
    // var parames = new Array();
    //
    // parames.push({ name: "userstring", value: userString});
    // parames.push({ name: "token", value: token});
    // Post(mu, parames);

    var user_data = getData('scj_user');
    var userObj = JSON.parse(user_data);
    var uid = userObj.id;
    $(window).attr('location',host+'/index/index/simple?id='+uid);
    // $(window).attr('location',host+'/api/perdata/simpleShow?id='+uid);

    // var downloadTextFile = function(mobileCode) {
    //     if(isEmpty(mobileCode)) {
    //         mobileCode = '';
    //     }
    //
    //     var file = new File([mobileCode], "手机号.txt", { type: "text/plain;charset=utf-8" });
    //     var re = saveAs(file);
    //     showy(re);
    // }
    //
    // showy(downloadTextFile());

    // var url = 'https://zhidao.baidu.com/question/814847602979397772.html';
    // url = 'https://www.cnblogs.com/laotan/p/3958011.html';
    // url = 'https://www.aliyun.com/jiaocheng/611850.html';
    // showy('url: ' + url);
    // getUrlData(url,function (data) {
    //     showy('yu-title:' + data.title);
    //     showy('yu-keyword:' + data.keyword);
    //     showy('yu-desc:' + data.desc);
    // });

});

//点击密码工具的时候的一个动效
$('.btn-pass-user').click(function () {
    var user_data = getData('scj_user');
    var userObj = JSON.parse(user_data);
    var uid = userObj.id;
    $(window).attr('location',host+'/index/index/pas');
});

//点击我的消息的时候的一个动效
$('.btn-msg').click(function () {
    //跳转用户详细数据页
    var mu = host+'/index/index/msg';
    var parames = new Array();
    var token = token;
    var userString = userString;
    if (isEmptyString(token)){
        token = getData('scj_token');
        userString = getData('scj_user');
    }
    parames.push({ name: "userstring", value: userString});
    parames.push({ name: "token", value: token});
    Post(mu, parames);
});
//点击我的账户的时候的一个动效
$('.btn-data').click(function () {
    //跳转到我的账户
    var mu = host+'/index/userdata/data';
    var parames = new Array();
    var token = token;
    var userString = userString;
    if (isEmptyString(token)){
        token = getData('scj_token');
        userString = getData('scj_user');
    }
    parames.push({ name: "userstring", value: userString});
    parames.push({ name: "token", value: token});
    Post(mu, parames);
});